#!/bin/bash

rm -rf .temp
mkdir -p .temp

CS0=`md5sum $2 | ( read A B; echo $A)` && \
CS1=`md5sum $3 | ( read A B; echo $A)` && \
CS2=`md5sum $4 | ( read A B; echo $A)` && \
CSM=`md5sum $5 | ( read A B; echo $A)` && \
CSA=`echo "${CS0} ${CS1} ${CS2} ${CSM}" | md5sum | ( read A B; echo $A)` && \
cp $2 .temp/${CS0}.elf && \
cp $3 .temp/${CS1}.elf && \
cp $4 .temp/${CS2}.elf && \
cp $5 .temp/${CSM}.elf && \
bash -c 'echo -e "\033[032mUploading files\033[0m"' && \
rsync -avz .temp/ $1:elfs && \
bash -c 'echo -e "\033[032mAsking server to run our project\033[0m"' && \
ssh $1 rdist ${CS0} ${CS1} ${CS2} ${CSM} && \
scp $1:${CSA}.ttylog $6

rm -rf .temp
